package com.supsi.segreteria.client;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: fabio
 * Date: 28.05.12
 * Time: 17:17
 * To change this template use File | Settings | File Templates.
 */
public class DummyConnection implements IConnection {
    private String serverAck;
    private ArrayList<String> returnMessage = new ArrayList<String>();

    @Override
    public void connect() throws UnknownHostException {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void close() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void sendMessage(String message) throws IOException {
        /*
           HELLO <nickname> - introduzione al sistema  (client -> server)
           MESSAGETO <nickname> <text>   (client -> server)
           GETMESSAGES [new] [all]   (client -> server)
           NEWMESSAGE  num (server -> client)
           DELMESSSAGE [all] [message_number]  - 1. messaggio piu' vecchio (client -> server)
           NOTIFY <number_of_new_messages> <number_of_all_messages> - alla registrazione del client (server -> client)
           ERROR <message> - messaggio descritivo */

        serverAck = "ERROR";

        if (message.startsWith ("HELLO")){
            if (message.equals("HELLO DUMMY")) {
                serverAck="NEWMESSAGES 1";
                returnMessage.add("DUMMY | | messaggio 1");
            } else {
                serverAck = "OK";
            }
        }
        if (message.startsWith("MESSAGETO")) {
            serverAck = "OK";
        }
        if (message.startsWith("GETMESSAGES")) {
            serverAck = "OK";
        }
        if (message.startsWith("NEWMESSAGE")) {
            serverAck = "OK";
        }
        if (message.startsWith("DELMESSSAGE")) {
            serverAck = "OK";
        }
    }

    @Override
    public String getServerAck() {
        return serverAck;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ArrayList<String> getMessages() {
        return returnMessage;
    }
}
